﻿@using Microsoft.Web.Mvc
@using SapaFinance.DTO
@using SapaFinance.UI.Controllers
@using Telerik.Web.Mvc.UI
@model IEnumerable<OrderDTO>
@{
    ViewBag.Title = "Список распоряжений";
}
<h2>
    Список распоряжений</h2>
  @{ Html.RenderAction<UserController>(x => x.RenderOwners(Guid.Empty)); }
  @*<div class="editor-field">@(Html.Telerik().DropDownList().Name("SelectedOwner").BindTo(@Model).ClientEvents(x => x.OnChange("loadOrdersBySelectedUser").OnDataBound("loadOrdersBySelectedUser")))</div>*@
@*columns.Template(@<text>
    <input name="checkedRecords" type="checkbox" value="@item.UID" title="checkedRecords" /></text>).Width(50).HtmlAttributes(new { style = "text-align:center" });*@
@*columns.Bound(o => o.Number).Sortable(false).Filterable(false).ClientTemplate("<input type='checkbox' name='checkedRecords' onclick='MarkSelection()' value='<#= Id #>' />")
                            .Title("").Width(36).HtmlAttributes(new { style = "text-align:center" });*@
@*columns.Template(@<text>
    <input name="checkedRecords" type="checkbox" value="@item.UID" title="checkedRecords" onclick='MarkSelection()'/></text>).Width(50).HtmlAttributes(new { style = "text-align:center" });*@
<div>
    
</div>
<p>
    <button class="t-button t-state-default" onclick="displayCheckedOrders()">
        Выбрать распоряжения</button>
</p>
<div id="actorselectorders">
</div>
@Html.ValidationSummary(true)
<script type="text/javascript">
    function displayCheckedOrders() {
        var $checkedRecords = $(':checked');

        if ($checkedRecords.length < 1) {
            alert('Ни одно распоряжение не выбрано');
            return;
        }
        $('#actorselectorders').load('@Url.Action("DisplayCheckedOrders", "Order")', $checkedRecords);
    }

    function masterCheck(obj) {
        if ($(obj).attr('checked')) {
            $(':checkbox').attr('checked', 'checked');
        } else {
            $(':checkbox').removeAttr('checked');
        }
    }
    function slaveCheck() {
        var numChkBoxes = $('#MyTable input[type=checkbox][id!=mastercheckbox]').length;
        var numChkBoxesChecked = $('#MyTable input[type=checkbox][checked][id!=mastercheckbox]').length;
        if (numChkBoxes == numChkBoxesChecked && numChkBoxes > 0) {
            $('#mastercheckbox').attr('checked', 'checked');
        } else {
            $('#mastercheckbox').attr('checked', '');
        }
    }
</script>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        // MasterCheckBox functionality
        $('#mastercheckbox').click(function () {
            masterCheck(this);
        });
        $('#MyTable input[type=checkbox][id!=mastercheckbox]').click(function () {
            slaveCheck();
        });
        masterCheck($('#mastercheckbox'));
    });
</script>
<script type="text/javascript" language="javascript">
    function loadDetailByUser(e) {
        alert('edfef');
    }
</script>